package utils

import (
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/cache"
	"github.com/astaxie/beego/logs"
	_ "github.com/astaxie/beego/cache/redis"
)

var Cache cache.Cache

func init()  {
	bm, err := cache.NewCache("redis", fmt.Sprintf(
		`{"key":"%s","conn":"%s:%s","dbNum":"0","password":"%s"}`,
		"rcenet_cache",
		beego.AppConfig.DefaultString("redis_host", "127.0.0.1"),
		beego.AppConfig.DefaultString("redis_port", "6379"),
		beego.AppConfig.DefaultString("redis_auth", ""),
	))
	if err != nil {
		logs.Error(err)
	} else {
		logs.Info("redis cache contect ...")
		Cache = bm
	}
}
